package com.hxexp.weixin.test;

import java.util.HashMap;

import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hxexp.weixin.common.jsptag.CustomFunctions;
import com.hxexp.weixin.test.runner.JUnit4WithLogClassRunner;
import com.qq.weixin.common.security.WeixinSignatureUtil;
import com.qq.weixin.constant.AppDevConstant;

/**
 * @author li.jiang
 *
 */
@RunWith(JUnit4WithLogClassRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class CommonTester {
	private static final Logger LOGGER = LoggerFactory.getLogger(CommonTester.class);
    @Test
    public void test() {
        System.out.println(CustomFunctions.isEnableQRCheckin("635100001"));

        // File file = new File("D:/SystemOut.log");
        // String MD5 = SignatureHelper.encryptFileMD5(file);
        // System.out.println(MD5);

        //        String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx09a52b00c181c032&redirect_uri=http%3A%2F%2Fweixin.huaxiaexpress.com%2Fweixinticket%2Ftrafficline%2Findex.do&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
        //        HttpGet httpget = new HttpGet(url);
        //        CloseableHttpClient httpclient = HttpClients.createDefault();
        //        httpget.setHeader("User-Agent", "micromessenger");
        //        try {
        //            String response = httpclient.execute(httpget, new BasicResponseHandler());
        //            System.out.println(response);
        //        } catch (ClientProtocolException e) {
        //            // TODO Auto-generated catch block
        //            e.printStackTrace();
        //        } catch (IOException e) {
        //            // TODO Auto-generated catch block
        //            e.printStackTrace();
        //        }

        //        String str = new String("");
        //        System.out.println((str == ""));
        //        java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");
        //        double v = 15;
        //        System.out.println(df.format(v));
        //        ArriveStationsParamBean param = new ArriveStationsParamBean();
        //        param.setStartCityId("1212");
        //        param.setStartStationId("stationId:223");
        //        System.out.println(JsonUtil.writeObject2JsonString(param));
        //        UUID uuid = UUID.randomUUID();
        //        System.out.println(uuid.toString().replace("-", ""));
        // byte[] randomBytes = new byte[6];
        // Random random = new Random(System.nanoTime());
        // random.nextBytes(randomBytes);

        //        for (int i = 0; i < 1; i++) {
        //            System.out.println(RandomUtil.getRandomString(32));
        //        }

        //        Random random = new Random(System.nanoTime());
        //        byte[] randomBytes = new byte[1];
        //        random.nextBytes(randomBytes);
        //        System.out.println(Hex.encodeHexString(randomBytes));
        //        System.out.println(RandomUtil.getRandomString(16));

        //        HashMap<String, String> paramMap = new HashMap<String, String>();
        //        paramMap.put("appid", "wxd930ea5d5a258f4f");
        //        paramMap.put("mch_id", "10000100");
        //        paramMap.put("device_info", "1000");
        //        paramMap.put("body", "test");
        //        paramMap.put("nonce_str", "ibuaiVcKdpRxkhJA");

        //        Map<String, String> sortedParamMap = SignatureHelper.sortMapByKey(paramMap);
        //        String sortedParamStr = sortedParamMap.toString().replaceAll(", ", "&").replaceAll("[{}]", "");
        //        System.out.println(sortedParamStr);
        //        sortedParamStr += String.format("&key=%s", AppDevConstant.WXPAY_API_SECRETKEY);
        //        System.out.println(sortedParamStr);
        //        String sign = SignatureHelper.encryptMD5(sortedParamStr);
        //        System.out.println(SignatureUtil.generatePaySign(paramMap));

        //        StringWriter sw = new StringWriter();
        //        try {
        //            JaxbMarshallerHelper.marshal(paramMap, sw);
        //        } catch (JAXBException e) {
        //            // TODO Auto-generated catch block
        //            e.printStackTrace();
        //        } catch (IOException e) {
        //            // TODO Auto-generated catch block
        //            e.printStackTrace();
        //        }
        //        System.out.println(sw.toString());

        //        ObjectMapper mapper = new ObjectMapper();
        //        HashMap<String, String> paramMap = new HashMap<String, String>();
        //        paramMap.put("name", "lijiang");
        //        paramMap.put("age", "33");
        //        paramMap.put("time", "10:30");
        //        String json = "";
        //        String json2 = "{\"errcode\":40029,\"errmsg\":\"invalid code\"}";
        //        try {
        //            json = mapper.writeValueAsString(paramMap);
        //            WebAccessTokenBean tokenBean = mapper.readValue(json2, WebAccessTokenBean.class);
        //            System.out.println("errcode: " + tokenBean.getErrcode());
        //            System.out.println("errmsg: " + tokenBean.getErrmsg());
        //            System.out.println(mapper.writeValueAsString(tokenBean));
        //        } catch (IOException e) {
        //            // TODO Auto-generated catch block
        //            e.printStackTrace();
        //        }
        //        System.out.println(json);

        //        System.out.println(String.format("%d%s", System.currentTimeMillis(), RandomUtil.getRandomString(3)));
        //
        //        System.out.println(System.currentTimeMillis()/1000);

        HashMap<String, String> payParamMap = new HashMap<String, String>(); // NOSONAR
        payParamMap.put("appId", "wx2421b1c4370ec43b");
        payParamMap.put("timeStamp", "1476758019");
        payParamMap.put("nonceStr", "H2nZWONRo8j8Z26X"); // NOSONAR
        payParamMap.put("package", "WAP");
        payParamMap.put("prepayid", "wx20161018103338aa8e205a6f0293982638");
        String sign = WeixinSignatureUtil.generatePaySign(AppDevConstant.HxExpTest.WXPAY_API_SECRETKEY, payParamMap);
        System.out.println(sign);
        LOGGER.info("sign={}", sign);
    }

}
